package com.lungle.warmdiary.app.utils;

/**
 * Created by zhangxueyuan on 2016/9/28.
 * level级别判断
 */

/**
 * 级别模型，实习分享官、助理分享官、初级分享官、中级分享官、高级分享官、银牌分享官、金牌分享官、白金分享官、钻石分享官、首席分享官。
 * 升级经验值，0，50,100,200,400,800,1600，3200,6400,12800；实习升级到助理需要50，助理升级到初级再需要100，以此类推。
 * 0-50 50-150 150-350,350-700
 * <p>
 * 0 50 150 350 700
 */
public class LevelUtil {

    private int level = 0;
    private final int max = 12800;
    private int min_exp = 0;
    private int min_level = 0;

    private int level_exps = 50;

    private int exp_upgrade = 50;
    private final String base_name = "分享官";

    //拥有的经验
    private int exp = 0;

    //需要增加的经验
    private int upgrade = 0;

    public LevelUtil(int exp) {
        this.exp = exp;
        getLevel();
    }

    private int getLevel() {

        if (this.exp < this.level_exps) {

            this.upgrade = this.level_exps - this.exp;
            return this.level;
        } else {
            this.level += 1;
            this.exp_upgrade = this.exp_upgrade * 2;
            if (this.exp_upgrade > 12800)
                return this.level;
            this.level_exps += this.exp_upgrade;

            return getLevel();
        }

    }

    public String getLevelName() {
        String temp = "";
        switch (this.level) {
            case 0:
                temp = "实习";
                break;
            case 1:
                temp = "助理";
                break;
            case 2:
                temp = "初级";
                break;
            case 3:
                temp = "中级";
                break;
            case 4:
                temp = "高级";
                break;
            case 5:
                temp = "银牌";
                break;
            case 6:
                temp = "金牌";
                break;
            case 7:
                temp = "白金";
                break;
            case 8:
                temp = "钻石";
                break;
            case 9:
                temp = "首席";
                break;
            default:
                temp = "首席";
        }
        return String.format("%s%s", temp, base_name);
    }

    public int getUpgrade() {
        return upgrade;
    }

    public int getLevelNum() {
        return this.level;
    }

    public static void main(String s[]) {
        LevelUtil l = new LevelUtil(51150);

        System.out.println("" + l.level);
        System.out.println("" + l.getLevelName() + " " + l.upgrade);

        l = new LevelUtil(1);
        System.out.println("" + l.level);
        System.out.println("" + l.getLevelName() + " " + l.upgrade);


        l = new LevelUtil(50);
        System.out.println("" + l.level);
        System.out.println("" + l.getLevelName() + " " + l.upgrade);

        l = new LevelUtil(100);
        System.out.println("" + l.level);
        System.out.println("" + l.getLevelName() + " " + l.upgrade);


        l = new LevelUtil(150);
        System.out.println("" + l.level);
        System.out.println("" + l.getLevelName() + " " + l.upgrade);

        l = new LevelUtil(360);
        System.out.println("" + l.level);
        System.out.println("" + l.getLevelName() + " " + l.upgrade);
    }
}